package de.pixel83.piecemaster;
// Copyright (c) 2012 Christian Kollross / Michael Freymueller

public class Square {
	public final int col;
	public final int row;

	/**
	 * Constructor expecting a String between a1 and e6
	 * 
	 * @param dim
	 */
	public Square(String dim) {
		assert (dim.length() == 2);

		col = dim.charAt(0) - 'a';
		row = dim.charAt(1) - '1';

		assert (col >= 0 && col <= 4);
		assert (row >= 0 && row <= 5);
	}

	/**
	 * Constructor expecting int values starting from 0.
	 * 
	 * @param col
	 *            Values 0-4
	 * @param row
	 *            Values 0-5
	 */
	public Square(int col, int row) {
		this.col = col;
		this.row = row;
	}

	public String toString() {
		return "" + (char) (col + 'a') + (row + 1);
	}

	public static void main(String[] args) {
		Square square;
		System.out.println("Testing Square...");

		square = new Square("a1");
		assert (square.col == 0 && square.row == 0);

		square = new Square("e6");
		assert (square.col == 4 && square.row == 5);

		square = new Square(3, 2);
		assert (square.col == 3 && square.row == 2);

		square = new Square(3, 2);
		assert (square.toString().equals("d3"));

		System.out.println("SUCCESS - All Square tests passed.");
	}
}
